/**
 * Exam No: Y8467136
 */
package japrc2011test;

import static org.junit.Assert.*;
import japrc2011.GridLocation;
import japrc2011.Robot;
import japrc2011.RobotException;
import japrc2011.RobotSimulator;
import japrc2011.SimulatorInterface;

import org.junit.Before;
import org.junit.Test;

public class SimulationLevel3Test {

    private SimulatorInterface rs;
    //Robot r;
    
    @Before
    public void setUp() throws Exception
    {
        rs = new RobotSimulator();
    }
    
    /**
     * The robot does not execute any of the commands while it is waiting
     */
	@Test
	public void testWaitMethod() {
		rs.addRobot(new Robot("r1"));
		rs.sendCommand("r1", "WAIT 2000");
		rs.sendCommand("r1", "M 1 0");
		rs.tick();
		assertEquals(new GridLocation(0,0), rs.getRobot("r1").getLocation());
		rs.sendCommand("r1", "M 1 0");
		rs.tick();
		assertEquals(new GridLocation(0,0), rs.getRobot("r1").getLocation());
		rs.sendCommand("r1", "STOP");
		assertEquals(2, rs.getRobotInfo("r1", "COMMAND_COUNT"));
	}
	
	
	/**
	 * Test the interval given in the REPEAT command
	 */
	@Test
	public void testIntervalOfRepeatCommand() {
		rs.addRobot(new Robot("r1"));
		try
		{
			rs.sendCommand("r1", "REPEAT (M 1 0) (-2000)");
			fail();
        } 
		catch (RobotException e) 
        { 
			
        }
	}
	
	
	/**
	 * Nested repeat commands are not supported
	 */
	@Test
	public void testRepeatNestedCommand() {
		rs.addRobot(new Robot("r1"));
		try
		{
			rs.sendCommand("r1", "REPEAT (REPEAT (M 1 0) (2000)) (2000)");
			fail();
        } 
		catch (RobotException e) 
        { 
			
        }
	}
}
